import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_massage/global.dart';
import 'package:flutter_massage/values/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

import 'common_lib/routers/route.dart';

Future main() async {
  await Global.init();
  runApp(MyApp(await CommonRoute.getRootPage()));

  // runApp(MyApp(SplashPage()));
}

class MyApp extends StatelessWidget {
  const MyApp(this.home, {Key? key}) : super(key: key);

  final Widget home;

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(375, 667),
      builder: (context, child) {
        return RefreshConfiguration(
          headerBuilder: () => const ClassicHeader(), //自定义刷新头部
          footerBuilder: () => const ClassicFooter(), //自定义刷新尾部
          hideFooterWhenNotFull: true, //当列表不满一页时，是否隐藏刷新尾部
          shouldFooterFollowWhenNotFull: (state) => false, //当列表不满一页时，刷新尾部是否跟随
          headerTriggerDistance: 80, //触发刷新的距离
          maxOverScrollExtent: 100, //最大的拖动距离
          footerTriggerDistance: 100, //触发加载的距离
          child: GetMaterialApp(
            title: 'massage',
            themeMode: ThemeMode.light,
            theme: ThemeData(
              canvasColor: Colors.white,
              appBarTheme: const AppBarTheme(color: AppColors.white),
            ),

            localizationsDelegates: const [
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
              GlobalCupertinoLocalizations.delegate,
            ],

            supportedLocales: const [
              Locale('zh', 'CH'),
              Locale('en', 'US'),
            ],
            locale: const Locale('zh'),

            /// 路由
            home: home,
            navigatorObservers: [FlutterSmartDialog.observer],

            /// builder
            builder: FlutterSmartDialog.init(builder: (context, widget) {
              widget = EasyLoading.init()(context, widget);

              /// 不随系统字体缩放比例
              return MediaQuery(
                data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
                child: widget,
              );
            }),

            /// 不显示debug角标
            debugShowCheckedModeBanner: false,
            defaultTransition: Transition.cupertino,
          ),
        );
      },
    );
  }
}
